<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>


<style>
  #div-parent {
    width: 600px;
    height: 20px;
    background: #CCC;
    position: relative;

  }

  #div1 {
    width: 20px;
    height: 20px;
    background: red;
    position: absolute;
    left: 0;
    top: 0;
  }

  #div2 {
    width: 0px;
    height: 0px;
    background: green;
  }
</style>

<script>
  window.onload = function () {
    let div_parent = document.getElementById("div-parent")
    let div1 = document.getElementById("div1")
    let div2 = document.getElementById("div2")
    let disX = 0

    div1.onmousedown = function (event) {
      dixX = event.clientX - div1.offsetLeft

      document.onmousemove = function (event) {
        let l = event.clientX - disX
        if (l < 0) {
          l = 0
        } else if (l > div_parent.offsetWidth - div1.offsetWidth) {
          l = div_parent.offsetWidth - div1.offsetWidth
        }
        div1.style.left = l + "px"
        let scale = (div1.offsetLeft + div1.offsetWidth) / div_parent.offsetWidth
        console.log(scale);
        
        div2.style.width = 400 * scale + "px"
        div2.style.height = 400 * scale + "px"
      }
      document.onmouseup = function () {
        document.onmousemove = null
        document.onmouseup = null
      }
      return false

    }
  }



</script>

<body>
  <div id="div-parent">
    <div id="div1"></div>
  </div>
  <div id="div2"></div>

</body>

</html>